package com.sea.demo.shiro.controller;

import com.sea.demo.shiro.domain.User;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 快乐在角落里
 * @Create: 2020/11/11 6:39
 */
@RestController
@RequestMapping("/logout")
public class LogoutController {

    private final Logger LOGGER = LogManager.getLogger(LogoutController.class);

    @RequestMapping(method = RequestMethod.POST)
    @RequiresAuthentication
    public String logout(){
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        SecurityUtils.getSubject().logout();
        LOGGER.info("LOGOUT SUCCESS! --------- {}",user.getUsername());
        return "退出成功!";
    }
}
